var seta;
var setb;
var setc;
var hh = 0; //小时
var mm = 0; //分钟
var ss = 0; //秒
var zs = 0; //当前创建的苹果数
var zq = 0; //正确个数
var z = 100; //总苹果数
window.onkeydown = function() {
	var key = event.keyCode;
	var top1 = document.getElementById("top1");
	var zqgs = document.getElementById("zqgs");
	for(var i = 0; i < top1.children.length; i++) {
		var code = top1.children[i].getAttribute("keycode");
		if(key == code) {
			top1.removeChild(top1.children[i]);
			zq++;
			break;
		}
	}
	var zql = document.getElementById("zql");
	var zl = zq / z;
	zql.innerHTML = zl * 100 + "%"
	zqgs.innerHTML = zq;
	switch(zq) {
		case 10:
			document.getElementById("a1").style.display = "block";
			break;
		case 20:
			document.getElementById("a2").style.display = "block";
			break;
		case 30:
			document.getElementById("a3").style.display = "block";
			break;
		case 40:
			document.getElementById("a4").style.display = "block";
			break;
		case 50:
			document.getElementById("a5").style.display = "block";
			break;
		case 60:
			document.getElementById("a6").style.display = "block";
			break;
		case 70:
			document.getElementById("a7").style.display = "block";
			break;
		case 80:
			document.getElementById("a8").style.display = "block";
			break;
		case 90:
			document.getElementById("a9").style.display = "block";
			break;
		case 100:
			document.getElementById("a10").style.display = "block";
			break;
		default:
			break;
	}
}

function kaishi() {
	clearInterval(seta);
	clearInterval(setb);
	clearInterval(setc);
	seta = setInterval("createPG()", 1000); //创建苹果
	setb = setInterval("movePG()", 100); //移动苹果
	setc = setInterval("time()", 1000); //时间
}

function createPG() {
	//出苹果个数不超过100个
	if(zs < z) {
		var div = document.createElement("div"); //创建苹果
		var num = parseInt(Math.random() * 26) + 65; //随机大写字母
		div.innerHTML = "&#" + num + ";";
		div.setAttribute("keyCode", num);
		var left = parseInt(Math.random() * 700) + 10; //随机位置
		div.style.left = left + "px";
		div.style.top = "0px";
		document.getElementById("top1").appendChild(div);
		var zgs = document.getElementById("zgs");
		zs++;
		zgs.innerHTML = zs;
	}

}
var j = 0;

function movePG() {
	//超出屏幕高度自动隐藏
	var top1 = document.getElementById("top1");
	for(var i = 0; i < top1.children.length; i++) {
		var t = parseInt(top1.children[i].style.top); //t为每个苹果的top
		t += 10;
		top1.children[i].style.top = t + "px";
		if(t > 370) {
			top1.children[i].innerHTML = "";
			top1.children[i].className = "psPG";

		}
		if(t > 400) {
			top1.removeChild(top1.children[i]);
			j++;
		}
		if(j >= 10) {
			jieshu();
		}
	}
}

function zanting() {
	clearInterval(seta);
	clearInterval(setb);
	clearInterval(setc);
}

function jieshu() {
	var top = document.getElementById("top1");
	var time = document.getElementById("sj");
	top.innerHTML = null;
	ss = 0;
	mm = 0;
	hh = 0;
	zs = 0;
	var zgs = document.getElementById("zgs");
	zgs.innerHTML = 0;
	time.innerHTML = "00:00:00";
	clearInterval(seta);
	clearInterval(setb);
	clearInterval(setc);
}

function shezhi() {
	var shez = document.getElementById("shezhi");
	shez.style.display = black;
}

function time() {
	ss++;
	if(ss == 60) {
		mm++;
		ss = 1;
	}
	if(mm == 60) {
		hh++;
		mm = 0;
	}
	var time = document.getElementById("sj");
	time.innerHTML = (hh - 10 > 0 ? hh : "0" + hh) + ":" + (mm - 10 > 0 ? mm : "0" + mm) + ":" + (ss - 10 >= 0 ? ss : "0" + ss);
}